package Views;

import javax.swing.ImageIcon;

public enum TabIndex
{
    Customers(0),
    Locations(1),
    Routes(2),
	Rounds(3),
	Employees(4),
	Cars(5),
	Schedules(6),
	Search(7);

    private int tabIndex;

	/**
	 * Initialiserer indexet
	 * @param index Indexet
	 */
    TabIndex(int index)
    {
        tabIndex = index;
    }

	/**
	 * Returnerer indexet
	 * @return Index
	 */
    public int getIndex()
    {
        return(tabIndex);
    }

	/**
	 * Returnerer titlen
	 * @return Titel
	 */
	public String getTitle()
	{
		String title = "";
		switch(tabIndex)
		{
			case 0:
				title = "Kunder";
				break;
			case 1:
				title = "Lokationer";
				break;
			case 2:
				title = "Ruter";
				break;
			case 3:
				title = "Runder";
				break;
			case 4:
				title = "Ansatte";
				break;
			case 5:
				title = "Biler";
				break;
			case 6:
				title = "Vagtplaner";
				break;
			case 7:
				title = "Søgning";
				break;
		}
		return title;
	}

	/**
	 * Returnerer billedet
	 * @return Billede
	 */
	public ImageIcon getImage()
	{
		ImageIcon image = new ImageIcon();
		switch(tabIndex)
		{
			case 0:
				image = getImage("customers");
				break;
			case 1:
				image = getImage("locations");
				break;
			case 2:
				image = getImage("routes");
				break;
			case 3:
				image = getImage("rounds");
				break;
			case 4:
				image = getImage("employees");
				break;
			case 5:
				image = getImage("cars");
				break;
			case 6:
				image = getImage("schedules");
				break;
			case 7:
				image = getImage("search");
				break;
		}
		return image;
	}

	/**
	 * Returnerer billedet for det givne tab
	 * @param section Tab'ens navn
	 * @return Billedet for det givne tab
	 */
	private ImageIcon getImage(String section)
	{
		return new ImageIcon(getClass().getResource("/Views/resources/"+section+".png"));
		/*java.net.URL imgURL = MainView.class.getResource("resources/"+section+".png");
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: "+section);
            return null;
        }*/
	}

	/**
	 * Returnerer alle titlerne til TabIndex'ene
	 * @return En samling af titler
	 */
	public static String[] getTitles()
	{
		String[] theTitles = { TabIndex.Customers.getTitle(),
								TabIndex.Locations.getTitle(),
								TabIndex.Routes.getTitle(),
								TabIndex.Rounds.getTitle(),
								TabIndex.Employees.getTitle(),
								TabIndex.Cars.getTitle(),
								TabIndex.Schedules.getTitle() };
		return theTitles;
	}

	/**
	 * Returnerer alle billeder til TabIndex'ene
	 * @return En samling billeder
	 */
	public static ImageIcon[] getImages()
	{
		ImageIcon[] theImages = { TabIndex.Customers.getImage(),
								TabIndex.Locations.getImage(),
								TabIndex.Routes.getImage(),
								TabIndex.Rounds.getImage(),
								TabIndex.Employees.getImage(),
								TabIndex.Cars.getImage(),
								TabIndex.Schedules.getImage() };
		return theImages;
	}

	/**
	 * Returnerer tabbens index ud fra et TabIndex
	 * @param tab Tabbens navn
	 * @return Tabbens index
	 */
	public static int getIndexFromTabIndex(TabIndex tab)
	{
		int index = 0;
		if(tab.equals(TabIndex.Customers))
		{
			index = TabIndex.Customers.getIndex();
		}
		else if(tab.equals(TabIndex.Locations))
		{
			index = TabIndex.Locations.getIndex();
		}
		else if(tab.equals(TabIndex.Routes))
		{
			index = TabIndex.Routes.getIndex();
		}
		else if(tab.equals(TabIndex.Rounds))
		{
			index = TabIndex.Rounds.getIndex();
		}
		else if(tab.equals(TabIndex.Employees))
		{
			index = TabIndex.Employees.getIndex();
		}
		else if(tab.equals(TabIndex.Cars))
		{
			index = TabIndex.Cars.getIndex();
		}
		else if(tab.equals(TabIndex.Schedules))
		{
			index = TabIndex.Schedules.getIndex();
		}
		else if(tab.equals(TabIndex.Search))
		{
			index = TabIndex.Search.getIndex();
		}
		return index;
	}

	public static TabIndex getTabIndexFromIndex(int index)
	{
		TabIndex tab = null;
		if(index == TabIndex.Customers.getIndex())
		{
			tab = TabIndex.Customers;
		}
		else if(index == TabIndex.Locations.getIndex())
		{
			tab = TabIndex.Locations;
		}
		else if(index == TabIndex.Routes.getIndex())
		{
			tab = TabIndex.Routes;
		}
		else if(index == TabIndex.Rounds.getIndex())
		{
			tab = TabIndex.Rounds;
		}
		else if(index == TabIndex.Employees.getIndex())
		{
			tab = TabIndex.Employees;
		}
		else if(index == TabIndex.Cars.getIndex())
		{
			tab = TabIndex.Cars;
		}
		else if(index == TabIndex.Schedules.getIndex())
		{
			tab = TabIndex.Schedules;
		}
		else if(index == TabIndex.Search.getIndex())
		{
			tab = TabIndex.Search;
		}
		return tab;
	}
}